package com.video.Controller;

import com.video.entity.Subject;
import com.video.entity.User;
import com.video.service.SubjectService;
import com.video.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("subject")
public class SubjectController {
    @Autowired
    public SubjectService subjectService;
    @Autowired
    public UserService userService;

    @RequestMapping("selectAll")
    public String selectAll(Model model){
        List<Subject> subjectList = subjectService.findAll();
        model.addAttribute("subjectList",subjectList);
        return "/before/index.jsp";
    }

    @RequestMapping("user/showMyProfile")
    public String showMyProfile(Model model, HttpServletRequest request) {
        User loginUser = (User) request.getSession().getAttribute("user");
        User user = userService.findById(loginUser.getId());
        model.addAttribute("user", user);
        request.getSession().setAttribute("user", user);
        return "/before/my_profile.jsp";
    }

}
